<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-9-08
 * Time: 下午3:49
 * 第一次创建角色性别分布
 */
include 'header.php';
$where = "1=1";
if (!empty($_GET)) {
    if (!empty($_GET['bt'])) {
        $bt = date('ymd0000', strtotime($_GET['bt'] . ' 00:00:00'));
        $where .= " AND i.createtime>=$bt";
    }
    if (!empty($_GET['et'])) {
        $et =  date('ymd2359', strtotime($_GET['et'] . ' 23:59:59'));
        $where .= " AND i.createtime<=$et";
    }
    if (is_numeric($_GET['userid']) && $_GET['userid']>0) {
        $where .= " AND userid=" . $_GET['userid'];
    }
    if (is_numeric($_GET['accountid']) && $_GET['accountid']>0) {
        $where .= " AND accountid=" . $_GET['accountid'];
    }
    if (is_numeric($_GET['serverid']) && $_GET['serverid']>0) {
        $where .= " AND serverid=" . $_GET['serverid'];
    }
}
else {
    $et = date('ymd0000');
    $bt = date('ymd2359');
    $where .= " AND i.createtime>$bt AND i.createtime<$et";
}
$total_sql = "SELECT COUNT(*) FROM palyerlogin l LEFT JOIN playrinfo i ON i.accountid=l.accountid WHERE {$where}";
$stmt = $db_source->prepare($total_sql);
$stmt->execute();
$total_rows = $stmt->fetchColumn(0);
if ($total_rows) {
    $sql = "SELECT * FROM palyerlogin l LEFT JOIN playrinfo i ON i.accountid=l.accountid WHERE " . $where . " ORDER BY day DESC LIMIT $offset,$pageSize";
    echo $sql;
    $stmt = $db_source->prepare($sql);
    $stmt->execute();
    $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <!-- /.panel-heading -->
            <div class="panel-heading">
                <form id="frm" class="form-inline" role="form" method="get">
                    <div class="form-group">
                        <label>Date</label>
                        <input type="text" name="bt" class="form-control" size="12" value="<?=$_GET['bt']?$_GET['bt']:date('Y-m-d');?>" />
                        to
                        <input type="text" name="et" class="form-control" size="12" value="<?=$_GET['et']?$_GET['et']:date('Y-m-d');?>" />
                    </div>
                    <div class="form-group">
                        <label>User ID</label>
                        <input name="userid" type="text" size="10" class="form-control"
                               value="<?=$_GET['userid']?>" >
                    </div>
                    <div class="form-group">
                        <label>Account ID</label>
                        <input name="accountid" type="text" size="10" class="form-control"
                               value="<?=$_GET['accountid']?>" >
                    </div>
                    <div class="form-group">
                        <label>Server</label>
                        <?php echo htmlSelect($serversList, 'serverid', $_GET['serverid']);?>
                    </div>
                    <button type="submit" id="BtnSearch" class="btn btn-primary">SEARCH</button>
                </form>
                <div class="count_result">
                    统计：<?=$total_rows?>
                </div>
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th><?=$lang['date']?></th>
                                <th>User Id</th>
                                <th>Account Id</th>
                                <th><?=$lang['server']?></th>
                                <th><?=$lang['channel']?></th>
                                <th><?=$lang['lev']?></th>
                                <th><?=$lang['money']?></th>
                                <th><?=$lang['emoney']?></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php if(isset($data)):?>
                            <?php foreach($data as $row):?>
                            <tr>
                                <td><?=$row['day']?></td>
                                <td><?=$row['userid']?></td>
                                <td><?=$row['accountid']?></td>
                                <td><?=$row['serverid']?></td>
                                <td><?=$row['fenbaoid']?></td>
                                <td><?=$row['lev']?></td>
                                <td><?=$row['money']?></td>
                                <td><?=$row['emoney']?></td>
                            </tr>
                            <?php endforeach;?>
                        <?php endif;?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="10"><?php page($total_rows,$currentPage,$pageSize);?></td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php include 'footer.php';?>
